package com.lot.ws.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	static final int FIX_DATE_LENGTH = 16;
	
	public static String makeFixedLength(String dateStr) {
		String a = "";
		for (int i = dateStr.length(); i < FIX_DATE_LENGTH + 1; i++) {
			a = a + "0";
		}
		return a + dateStr;
	}
	
	public static Date getDate(String dateString)
	{
		Date returnDate = null;
		try {
			returnDate = new SimpleDateFormat("dd/MM/yyyy hh:mm").parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}	
		return returnDate;
	}
	
	public static Date getRecordingDate(String dateString)
	{
		Date returnDate = null;
		try {
			returnDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}	
		return returnDate;
	}
	
	public static String converDateFormat(final String OLD_FORMAT, final String NEW_FORMAT, final String oldDateString)
	{
		String newDateString;
		SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
		Date d = null;
		try {
			d = sdf.parse(oldDateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		sdf.applyPattern(NEW_FORMAT);
		newDateString = sdf.format(d);
		return newDateString;
	}
	
	public static String convertDateFormat(final Date date, final String NEW_FORMAT)
	{
		String newDateString;
		SimpleDateFormat sdf = new SimpleDateFormat(NEW_FORMAT);
		sdf.format(date);
		newDateString = sdf.format(date);
		return newDateString;
	}
	
}
